package special_tree;

import compiler.CompilerException;

import code.CodeList;
import code.Opcode;
import lexer.Token;
import tree.DataType;
import tree.MyTree;
import tree.Tree;
import tree.Type;
import tree.TypingException;

public class OutputTree extends MyTree {

	@Deprecated
	Type typ;
	
	public OutputTree(Token token, Tree expr) {
		super(token, expr);
	}

	/* (non-Javadoc)
	 * @see tree.MyTree#computeType()
	 */
	@Override
	@Deprecated
	public Type computeType() throws TypingException {
		typ = this.expectType(getOperand(0), new Type(DataType.INT,""),
				new Type(DataType.DOUBLE, ""), new Type(DataType.CHAR, ""),
				new Type(DataType.BOOL, ""));
		return new Type(DataType.VOID, "");
	}

	/* (non-Javadoc)
	 * @see tree.MyTree#generateCode(code.CodeList)
	 */
	@Override
	@Deprecated
	public void generateCode(CodeList code) throws CompilerException {
		getOperand(0).generateCode(code);
		if (this.typ.equals(new Type(DataType.INT, ""))) {
			code.generateCode(Opcode.WRITEINT);
		}
		else if (this.typ.equals(new Type(DataType.DOUBLE, ""))) {
			code.generateCode(Opcode.WRITEDOUBLE);
		}
		else if (this.typ.equals(new Type(DataType.CHAR, ""))) {
			code.generateCode(Opcode.WRITECHAR);
		}
		else if (this.typ.equals(new Type(DataType.BOOL, ""))) {
			code.generateCode(Opcode.WRITEBOOL);
		}
	}

}
